package com.huiyi.healthWay.service.impl;

import java.util.List;

import com.huiyi.common.annotation.DataScope;
import com.huiyi.common.core.domain.entity.SysUser;
import com.huiyi.common.utils.StringUtils;
import com.huiyi.common.utils.spring.SpringUtils;
import com.huiyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.huiyi.healthWay.mapper.UserDataMapper;
import com.huiyi.healthWay.domain.UserData;
import com.huiyi.healthWay.service.IUserDataService;

/**
 * 用户Service业务层处理
 * 
 * @author zfz
 * @date 2024-10-15
 */
@Service
public class UserDataServiceImpl implements IUserDataService 
{
    @Autowired
    private UserDataMapper userDataMapper;

    /**
     * 查询用户
     * 
     * @param id 用户主键
     * @return 用户
     */
    public UserData selectUserDataById(Long id)
    {
        return userDataMapper.selectUserDataById(id);
    }

    /**
     * 查询用户列表
     * 
     * @param userData 用户
     * @return 用户
     */
    @Override
    @DataScope(userAlias = "u",deptAlias = "d")
    public List<UserData> selectUserDataList(UserData userData)
    {
        SysUser sysUser = SpringUtils.getBean(ISysUserService.class).selectUserByUserName(userData.getName());
        if (StringUtils.isNotNull(sysUser)){
        userData.setId(sysUser.getUserId());
        }
        return userDataMapper.selectUserDataList(userData);
    }

    /**
     * 新增用户
     * 
     * @param userData 用户
     * @return 结果
     */
    @Override
    public int insertUserData(UserData userData)
    {
        return userDataMapper.insertUserData(userData);
    }

    /**
     * 修改用户
     * 
     * @param userData 用户
     * @return 结果
     */
    @Override
    public int updateUserData(UserData userData)
    {
        return userDataMapper.updateUserData(userData);
    }

    /**
     * 批量删除用户
     * 
     * @param ids 需要删除的用户主键
     * @return 结果
     */
    @Override
    public int deleteUserDataByIds(Long[] ids)
    {
        return userDataMapper.deleteUserDataByIds(ids);
    }

    /**
     * 删除用户信息
     * 
     * @param id 用户主键
     * @return 结果
     */
    @Override
    public int deleteUserDataById(Long id)
    {
        return userDataMapper.deleteUserDataById(id);
    }
}
